package ast;

import java.util.ArrayList;

import symbol.FuncParamsTypeList;
import symbol.astPreprocessContext;

public class MainFunc extends AstItem {
	// 主函数
	// 语句块，BlockStatement类
	public AstItem mainFuncBlock;
	
	public String toString() {
		return "int main() " + mainFuncBlock.toString();
	}
	
	public void preprocess(AstItem father) {
		astPreprocessContext.getContext();
		// 建立函数变量记录表
		astPreprocessContext.createFuncTables("Main", new FuncParamsTypeList(new ArrayList<String>(), "int"));
		// 建立符号表，并把形参填进去
		astPreprocessContext.createSymbolTables("Main", new FuncParamsTypeList(new ArrayList<String>(), "int"), new ArrayList<String>());
		mainFuncBlock.preprocess(this);
		astPreprocessContext.removeNowFuncKey();
	}

	@Override
	public String toJsonString() {
		String json = "{";
		json += "\"Type\": \"MainFunc\",";
		json += "\"MainFuncBlock\": " + mainFuncBlock.toJsonString();
		json += "}";
		return json;
	}
}
